#define _CRT_SECURE_NO_WARN 1
#include<stdio.h>
#include<stdlib.h>

int* nextGreaterElement(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize)
{
    int* ret = (int*)malloc(sizeof(int) * (nums1Size + nums2Size));
    int k = 0;
    for (int i = 0; i < nums1Size; i++)
    {
        int mid = k;
        for (int j = 0; j < nums2Size; j++)
        {
            if (nums1[i] == nums2[j])
            {
                for (int x = j; x < nums2Size; x++)
                {
                    if (nums1[i] < nums2[x])
                    {
                        ret[k++] = nums2[x];
                        break;
                    }
                }
                break;
            }
        }
        if (mid == k)
        {
            ret[k++] = -1;
        }
    }
    *returnSize = k;
    return ret;
}